package com.huirui.server.pojo.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.PositiveOrZero;
import lombok.Data;

import java.util.List;

@Data
@Schema(description = "秒杀商品数据传输对象")
public class SeckillProductDto {

    @Schema(description = "秒杀场次ID", example = "1001", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "秒杀场次ID不能为空")
    @Positive(message = "秒杀场次ID必须为正数")
    private Long seckillPeriodId;

    @Schema(description = "商品ID", example = "2001", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "商品ID不能为空")
    @Positive(message = "商品ID必须为正数")
    private Long productId;

    @Schema(description = "秒杀状态（0-未开始，1-进行中，2-已结束）", example = "1")
    @NotNull(message = "秒杀状态不能为空")
    private Long status;

    @Schema(description = "秒杀商品规格列表", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "秒杀商品规格列表不能为空")
    @Valid // 级联校验子对象
    private List<SeckillProductSpecificationDto> seckillProductSpecificationDtoList;

    @Data
    @Schema(description = "秒杀商品规格数据传输对象")
    public static class SeckillProductSpecificationDto {

        @Schema(description = "商品规格ID", example = "3001", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "商品规格ID不能为空")
        @Positive(message = "商品规格ID必须为正数")
        private Long productSpecificationId;

        @Schema(description = "库存数量", example = "100", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "库存数量不能为空")
        @PositiveOrZero(message = "库存数量不能为负数")
        private Long stock;

        @Schema(description = "已售数量", example = "20")
        @PositiveOrZero(message = "已售数量不能为负数")
        private Long saleCount;

        @Schema(description = "秒杀价格（单位：分）", example = "9900", requiredMode = Schema.RequiredMode.REQUIRED)
        @NotNull(message = "秒杀价格不能为空")
        @Positive(message = "秒杀价格必须为正数")
        private Long seckillPrice;
    }
}
